package com.pizza.control;

import java.rmi.RemoteException;

import javax.faces.context.FacesContext;

import com.pizza.abstrait.AbstractAdresse;
import com.pizza.database.IPizzaManager;
import com.pizza.database.PizzaManagerClient;

/**
 * Class AdresseBean
 *
 */
public class AdresseBean extends AbstractAdresse
{

	public void chooseAsNewLocation()
	{
		if (register())
			setForCommande();
	}

	public boolean register()
	{
		boolean retour = false;
		IPizzaManager pizzaManager = PizzaManagerClient.GetPizzaManager();
		FacesContext context = FacesContext.getCurrentInstance();
		ClientBean client = (ClientBean) context.getExternalContext().getSessionMap()
				.get("clientBean");
		try
		{
			retour = pizzaManager.addAdresse(client, this);
			client.setAdressesLivraison(pizzaManager.getListAdressesLivraison(client));
		} catch (RemoteException e)
		{
			e.printStackTrace();
		}
		return retour;
	}
}
